package com.noahplat.user.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.user.pojo.SysType;
import com.noahplat.user.service.SysTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;

/**
 * 系统类型相关操作
 *
 * @author 李东
 * @version 1.0.0
 * @Date: 2021/3/1 10:11
 **/

@RestController
@RequestMapping("/api/sys")
@Validated
public class SysTypeController {


    @Autowired
    private SysTypeService sysTypeService;

    /**
     * 查询系统信息
     *
     * @author 李东
     * @time 2021-02-27 10:15
     */
    @GetMapping("/getSysInfo")
    public Result getSysInfo(@NotEmpty(message = "参数不能为空") String sysType) {
        return sysTypeService.getSysInfoByName(sysType);
    }

    /**
     * 更新系统信息
     *
     * @author 李东
     * @time 2021-03-01 10:25
     */
    @PreAuthorize("hasAuthority('noahplat-service-user:SysTypeController:updateSysInfo')")
    @PostMapping("/updateSysInfo")
    public Result getSysInfo(@Validated SysType sysType) {
        return sysTypeService.updateSysInfo(sysType);
    }

    /**
     * 添加系统信息
     * @param sysType
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-user:SysTypeController:addSysType')")
    @PostMapping("/addSysType")
    public Result addSysType(@RequestBody SysType sysType){
        return sysTypeService.addSysType(sysType);
    }

    /**
     * 分页获取系统信息
     * @param page
     * @param limit
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-user:SysTypeController:getSysType')")
    @GetMapping("/getSysType")
    public Result getSysType(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer limit){
        return sysTypeService.getSysType(page, limit);
    }

    /**
     * 获取系统信息
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-user:SysTypeController:getAllSysType')")
    @GetMapping("/getAllSysType")
    public Result getAllSysType(){
        return sysTypeService.getAllSysType();
    }
}
